package org.pageley.games.sanctuary.domain.environment.room;

import java.util.Collection;
import java.util.HashSet;

import org.pageley.games.sanctuary.domain.Location;
import org.pageley.games.sanctuary.domain.SimpleLocation;
import org.pageley.games.sanctuary.domain.environment.AbstractEnvironment;
import org.pageley.games.sanctuary.domain.event.EventListener;

public abstract class AbstractRoom extends AbstractEnvironment implements Room, EventListener {
	private Location topLeft;
	private Collection<Location> nodes;

	public AbstractRoom(Location location) {
		this.topLeft = location;
	}

	@Override
	public Location getTopLeft() {
		return this.topLeft;
	}

	@Override
	public Collection<Location> getNodes() {
		if(nodes == null) {
			nodes = new HashSet<Location>();
			for(int x = 0; x < getWidth(); x++) {
				for(int y = 0; y < getHeight(); y++) {
					nodes.add(new SimpleLocation(getTopLeft().getX() + x, getTopLeft().getY() + y));
				}
			}
		}
		return nodes;
	}

}
